package ua.lviv.franko.visualisation;

import ua.lviv.franko.mlsFunctions.oneDimension.weightFunctions.IWeightFunction;

public class Derivaty {
	protected IWeightFunction	func;
	public static double		h	= 0.0001;

	public Derivaty(IWeightFunction func) {
		this.func = func;
	}

	public double calculate(double x, double xi, double rho) {
		return (func.calculate(x, xi, rho) - func.calculate(x - h, xi, rho)) / h;
	}

	public double calculate2(double x, double xi, double rho) {
		return (func.calculate(x + h, xi, rho) - 2 * func.calculate(x, xi, rho) + func.calculate(x - h, xi, rho)) / h / h;
	}

	public static double calculate(double x, double xi, double rho, IWeightFunction function) {
		return (function.calculate(x, xi, rho) - function.calculate(x - h, xi, rho)) / h;
	}

	public static double calculate2(double x, double xi, double rho, IWeightFunction function) {
		return (function.calculate(x + h, xi, rho) - 2 * function.calculate(x, xi, rho) + function.calculate(x - h, xi, rho)) / h / h;
	}

	public static void main(String[] args) {

	}

}
